﻿$(document).ready(function () {
//    Util.loadHeadSource("http://maps.google.com/maps/api/js?sensor=true", "js");
//    Util.loadHeadSource("http://maps.gstatic.com/intl/en_us/mapfiles/api-3/7/5/main.js", "js");
});



if (typeof (Util) == "undefined") { Util = {}; }

Util = {
    enableRibbonButtonBySingleItem: function (count) {
        if (count == 1)
            return true;

        return false;
    },

    enableRibbonButtonByMultipleItems: function (count) {
        if (count > 0)
            return true;

        return false;
    },

    isGoogleAvailable: function () {
        try {
            return ((google != null || google != undefined) && (google.maps.LatLng != null || google.maps.LatLng != undefined));
        }
        catch(e) {
            return false;
        }
    },

    showError: function (error) {
        this.showNotification('Opsss... An error has thrown: ' + error);
    },

    showNotification: function (message) {
        var messageID = SP.UI.Notify.addNotification(message, false, "", null);
    },

    showModal: function (title, url, html, height, width, maximized) {
        var dialogOptions = SP.UI.$create_DialogOptions();

        dialogOptions.title = title;

        if (html)
            dialogOptions.html = html;
        else if (url)
            dialogOptions.url = url;
        else {
            this.showNotification("Houston, we have a problem here. HTML or URL wasn't set correctly to open this Modal");
            return;
        }

        if (width)
            dialogOptions.width = width;
        if (height)
            dialogOptions.height = height;

        dialogOptions.showMaximized = maximized;
        SP.UI.ModalDialog.showModalDialog(dialogOptions);

    },

     loadHeadSource: function (source, type) {
        if (type == "js") {
            var fileref = document.createElement('script')
            fileref.setAttribute("type", "text/javascript")
            fileref.setAttribute("src", source)
        }
        else if (type == "css") {
            var fileref = document.createElement("link")
            fileref.setAttribute("rel", "stylesheet")
            fileref.setAttribute("type", "text/css")
            fileref.setAttribute("href", source)
        }
        else if (type == "meta") {
            var fileref = document.createElement("meta")
            fileref.setAttribute("content", "initial-scale=1.0, user-scalable=no")
            fileref.setAttribute("name", source)
        }

        if (typeof fileref != "undefined")
            document.getElementsByTagName("head")[0].appendChild(fileref)
    }
}